from qturboframe.lib.utils.CustomError.custom_error import CustomErrorC

class CustomException(Exception):
    '''
    异常类：自定义的异常类

    Attributes:
     - value: 错误的提示信息
     - extra_msg: 补充的异常信息说明

    :Example:
     - 例: CustomException('元素未找到！')
    '''

    def __init__(self, value, extra_msg = ''):
        if value.__class__.__name__ == 'CustomErrorC' and extra_msg:
            self.value = CustomErrorC(value.error_code,
                                      value.error_msg,
                                      extra_msg)
        else:
            #判断一下是不是间接抛出CustomErrorC的异常
            try:
                class_name = value.value.__class__.__name__
            except:
                class_name = None
            if class_name == 'CustomErrorC':
                self.value = CustomErrorC(value.value.error_code, value.value.error_msg, value.value.extra_msg)
            else:
                self.value = value

    def __str__(self):
        return repr(self.value)